#define  _CRT_SECURE_NO_WARNINGS 1

#include "Sort.h"

void TestMerge()
{
	int n = 50;
	int* arr = (int*)malloc(sizeof(int) * n);
	if (arr == NULL)
	{
		perror("malloc fail");
		exit(-1);
	}

	for (int i = 0; i < n; ++i)
	{
		arr[i] = rand() % 101;
	}

	PrintArray(arr, n);
	MergeSort(arr, n);
	PrintArray(arr, n);

}

void TestMergeNonR()
{
	int n = 50;
	int* arr = (int*)malloc(sizeof(int) * n);
	if (arr == NULL)
	{
		perror("malloc fail");
		exit(-1);
	}

	for (int i = 0; i < n; ++i)
	{
		arr[i] = rand() % 101;
	}

	PrintArray(arr, n);
	MergeSortNonR(arr, n);
	PrintArray(arr, n);

}

void TestCount()
{
	int n = 50;
	int* arr = (int*)malloc(sizeof(int) * n);
	if (arr == NULL)
	{
		perror("malloc fail");
		exit(-1);
	}

	for (int i = 0; i < n; ++i)
	{
		arr[i] = rand() % 101;
	}

	PrintArray(arr, n);
	CountSort(arr, n);
	PrintArray(arr, n);

}

void TestOP()
{
	int n = 1000000;
	int* arr1 = (int*)malloc(sizeof(int) * n);
	int* arr2 = (int*)malloc(sizeof(int) * n);
	int* arr3 = (int*)malloc(sizeof(int) * n);
	if (arr1 == NULL || arr2 == NULL || arr3 == NULL)
	{
		perror("malloc fail");
		exit(-1);
	}

	for (int i = 0; i < n; ++i)
	{
		arr1[i] = rand() % 100000;
		arr2[i] = arr1[i];
		arr3[i] = arr1[i];
	}

	int begin = clock();
	MergeSort(arr1, n);
	int end = clock();
	printf("MergeSort: %d\n", end - begin);

	begin = clock();
	MergeSortNonR(arr2, n);
	end = clock();
	printf("MergeSortNonR: %d\n", end - begin);

	begin = clock();
	CountSort(arr3, n);
	end = clock();
	printf("CountSort: %d\n", end - begin);

}

int main()
{
	srand((unsigned int)time(NULL));
	//TestMerge();
	//TestMergeNonR();
	//TestCount();
	TestOP();

	return 0;
}